package renamer;

import java.sql.Timestamp;
import java.util.LinkedList;

import movie.Movie;
import Download.Downloader;
import Filters.Filter;
import config.ConfigurationsFile;

public class Run {


	public void run(Timestamp time, ConfigurationsFile config) {

		/*
		 *  Star Runtime
		 * 4 Scrappe torrentbutler
		 * 5 Filter Movie List and Filter TorrentList
		 * 6 Download Torrent 
		 * 7 Add Movie to database
		 */

		//* 4 Scrappe torrentbutler
		LinkedList<Movie> movies=new LinkedList<Movie>();
		movies=scrape(movies);


		//	* 5 Filter Movie List and Filter TorrentList
		movies=filter(movies,config);
		
		// Print Movies
		print(movies);
		
		// * 6 Download Torrent
		movies=new Downloader().download(movies);
		// * 7 Add to database
		

	}

	private void print(LinkedList<Movie> movies) {
		for (Movie m:movies)
			System.out.println(m.text());
		
	}

	private LinkedList<Movie> filter(LinkedList<Movie> movies, ConfigurationsFile config) {
		return new Filter().filter(movies,config.getMinYear(),config.getMinRate(),config.getMinNumberSeeds(),config.getMinSize());

	}

	private LinkedList<Movie> scrape(LinkedList<Movie> movies) {
	
		movies= new parsers.LatestParser().parse("http://torrentbutler.eu");//ou latest??

		for(Movie m:movies){
			m.setTorrentList(new parsers.MovieParser().parse(m));
		}
		return movies;
	}

}
